package com.jpf.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jpf.service.OrderService;
@WebServlet("/DeleteOrder.do")
public class DeleteOrder extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		OrderService orderService = new OrderService();
		int oid =Integer.parseInt(request.getParameter("oid"));
		if(orderService.deleteOrder(oid))
			response.sendRedirect("QueryOrder.do");  
		else
		response.sendRedirect("admin/error.jsp");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		String order = request.getParameter("delorder");
		OrderService orderService = new OrderService();
		String[] strs = order.split(",");
		for (int i = 0; i < strs.length; i++) {
			try {
				int gid = Integer.parseInt(strs[i]);
				orderService.deleteOrder(gid);
			} catch (Exception e) {
			}
		}
	}

}
